package oa.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import oa.web.dao.AttendDao;
import oa.web.dao.BaseDao;
import oa.web.pojo.Attend;
import oa.web.pojo.Employee;

@Repository
public class AttendDaoImpl extends BaseDao implements AttendDao{

	@Override
	public String getNameSpace() {
		return "attend.";
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Attend> findByEmpAndDutyDay(int empId, String dutyDay) {
		Map params = new HashMap();
		params.put("empId", empId);
		params.put("dutyDate", dutyDay);
		List<Attend> attends = getSqlMapClientTemplate().queryForList(getNameSpace() + "getByEmpAndDutyDay",  params);
		
		logger.info("findByEmpAndDutyDay-----attends.size(): " + attends.size());
		
		return attends;
	}

	@Override
	public void save(Attend a) {

		getSqlMapClientTemplate().insert(getNameSpace() + "insertAttend", a);
		
	}

	@Override
	public Attend findByEmpAndDutyDayAndCome(int empId, String dutyDay,
			boolean isCome) {
		Map params = new HashMap();
		params.put("empId", empId);
		params.put("dutyDate", dutyDay);
		params.put("isCome", isCome ? 1 : 0);
		Attend attend = (Attend) getSqlMapClientTemplate().queryForObject(getNameSpace() + "getByEmpAndDutyDayAndCome", params);
		return attend;
	}

	@Override
	public void update(Attend a) {
		Map params = new HashMap();
		params.put("typeId", a.getTypeId());
		params.put("punchTime", a.getPunchTime());		
		params.put("empId", a.getAttend_id());
		getSqlMapClientTemplate().update(getNameSpace() + "updateAttend", params);
	}

	@Override
	public List<Attend> findByEmpAndDays(int empId, String startDay,
			String endDay) {
		Map params = new HashMap();
		params.put("startDay", startDay);
		params.put("endDay", endDay);
		List<Attend> attends = getSqlMapClientTemplate().queryForList(getNameSpace() + "getByEmpAndDays",  params);
		
		logger.info("findByEmpAndDays-----attends.size(): " + attends.size());
		
		return attends;
	}

}
